// 原生sql查询
const mysql1 = require("mysql");
// const { use } = require("../routes/loginRouter");
const pool = mysql1.createPool({
  host: "114.132.89.243",
  user: "root",
  password: "rn*wwdEH6-Sf",
  database: "pmc",
  multipleStatements: true, //是否允许执行多条sql语句
  timezone: '08:00' 
});
let query = function (sql, ...values) {
  // 返回一个 Promise
  return new Promise((resolve, reject) => {
    pool.getConnection(function (err, connection) {
      if (err) {
        reject(err);
      } else {
        connection.query(sql, values, (err, rows) => {
          if (err) {
            reject(err);
          } else {
            resolve(rows);
          }
          // 结束会话
          connection.release();
        });
      }
    });
  });
};
module.exports = query;